namespace ACRSAP.Issues
{
    using ASPNET.StarterKit.IssueTracker.BusinessLogicLayer;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Diagnostics;
    using System.Runtime.CompilerServices;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using ASPNET.UserControls;

    public class IssueList : Page
    {
        [AccessedThroughProperty("btnAdd")]
        private Button _btnAdd;
        [AccessedThroughProperty("ctlDisplayIssues")]
        private DisplayIssues _ctlDisplayIssues;
        [AccessedThroughProperty("dropProjects")]
        private PickProject _dropProjects;
        [AccessedThroughProperty("dropView")]
        private DropDownList _dropView;
        [AccessedThroughProperty("lblProjectName")]
        private Label _lblProjectName;
        private object designerPlaceholderDeclaration;

        public IssueList()
        {
            base.Load += new EventHandler(this.Page_Load);
            base.PreRender += new EventHandler(this.Page_PreRender);
            base.Init += new EventHandler(this.Page_Init);
        }

        public void AddIssue(object s, EventArgs e)
        {
            this.Response.Redirect("~/Issues/IssueDetail.aspx?pid=" + StringType.FromInteger(this.dropProjects.SelectedValue));
        }

        public void BindIssues()
        {
            IssueCollection colIssues = null;
            int projectId = this.dropProjects.SelectedValue;
            if (this.Page.User.IsInRole("Project Manager") | this.Page.User.IsInRole("Administrator"))
            {
                colIssues = Issue.GetIssuesByProjectId(projectId);
            }
            if (this.Page.User.IsInRole("Consultant"))
            {
                colIssues = Issue.GetIssuesByCreatorUsername(projectId, this.User.Identity.Name);
            }
            this.ctlDisplayIssues.DataSource = colIssues;
            this.ctlDisplayIssues.DataBind();
        }

        [DebuggerStepThrough]
        private void InitializeComponent()
        {
        }

        public void IssuesRebind(object s, EventArgs e)
        {
            this.BindIssues();
        }

        private void Page_Init(object sender, EventArgs e)
        {
            this.InitializeComponent();
        }

        private void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                if (this.Request.QueryString["pid"] != null)
                {
                    try
                    {
                        this.dropProjects.SelectedValue = int.Parse(this.Request.QueryString["pid"]);
                    }
                    catch (Exception exception1)
                    {
                        ProjectData.SetProjectError(exception1);
                        ProjectData.ClearProjectError();
                    }
                }
                this.dropProjects.DataSource = Project.GetProjectByMemberUsername(this.User.Identity.Name);
                this.dropProjects.DataBind();
                this.dropView.Visible = false;
                if (this.dropProjects.SelectedValue == 0)
                {
                    this.Response.Redirect("~/NoProjects.aspx");
                }
                this.BindIssues();
            }
        }

        private void Page_PreRender(object sender, EventArgs e)
        {
            if (this.Page.User.IsInRole("Guest"))
            {
                this.btnAdd.Enabled = false;
            }
        }

        public void ViewSelectedIndexChanged(object s, EventArgs e)
        {
            this.ctlDisplayIssues.CurrentPageIndex = 0;
            this.BindIssues();
        }

        protected virtual Button btnAdd
        {
            get
            {
                return this._btnAdd;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._btnAdd != null)
                {
                    this._btnAdd.Click -= new EventHandler(this.AddIssue);
                }
                this._btnAdd = value;
                if (this._btnAdd != null)
                {
                    this._btnAdd.Click += new EventHandler(this.AddIssue);
                }
            }
        }

        protected virtual DisplayIssues ctlDisplayIssues
        {
            get
            {
                return this._ctlDisplayIssues;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._ctlDisplayIssues != null)
                {
                    this._ctlDisplayIssues.RebindCommand -= new EventHandler(this.IssuesRebind);
                }
                this._ctlDisplayIssues = value;
                if (this._ctlDisplayIssues != null)
                {
                    this._ctlDisplayIssues.RebindCommand += new EventHandler(this.IssuesRebind);
                }
            }
        }

        protected virtual PickProject dropProjects
        {
            get
            {
                return this._dropProjects;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._dropProjects != null)
                {
                    this._dropProjects.SelectedIndexChanged -= new EventHandler(this.ViewSelectedIndexChanged);
                }
                this._dropProjects = value;
                if (this._dropProjects != null)
                {
                    this._dropProjects.SelectedIndexChanged += new EventHandler(this.ViewSelectedIndexChanged);
                }
            }
        }

        protected virtual DropDownList dropView
        {
            get
            {
                return this._dropView;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._dropView != null)
                {
                    this._dropView.SelectedIndexChanged -= new EventHandler(this.ViewSelectedIndexChanged);
                }
                this._dropView = value;
                if (this._dropView != null)
                {
                    this._dropView.SelectedIndexChanged += new EventHandler(this.ViewSelectedIndexChanged);
                }
            }
        }

        protected virtual Label lblProjectName
        {
            get
            {
                return this._lblProjectName;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._lblProjectName != null)
                {
                }
                this._lblProjectName = value;
                if (this._lblProjectName != null)
                {
                }
            }
        }
    }
}

